package com.fzrskj.cloud.free.user.service.diy;

import com.fzrskj.cloud.free.core.tool.CJsonTool;
import com.fzrskj.cloud.free.user.utils.diy.AgentDiyProductSetUtils;
import ms.core.consts.SysErr;
import ms.core.object.CObject;
import ms.core.tool.XmlCodeParser;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * AgentDiyProductSetService.
 *
 * @author zj.
 *         Created on 2020/1/14 0014.
 */
public class AgentDiyProductSetService extends CObject {
    /**
     * 代理自定义产品价格溢价率.
     * @param req
     * @param resp
     * @param p
     * @param sid
     * @return
     */
    public String saveDiyPricePremium (HttpServletRequest req, HttpServletResponse resp, String p, String sid){
        Double premium = CJsonTool.getDoubleVal(p, "premium", 0.0);
        Integer type = CJsonTool.getIntValue(p, "type", 1);
        if (premium < 0.0 || premium > 100 || type < 1 || type > 2) {
            return XmlCodeParser.formatCustomTips(false, SysErr.SYS_PARAM_ERR);
        }

        AgentDiyProductSetUtils setUtils = new AgentDiyProductSetUtils();
        setUtils.saveDiyPricePremium(type, premium);

        return XmlCodeParser.formatCustomTips(true, SysErr.CODE_SUCCESS);
    }
}
